<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String bathPath = request.getContextPath();
	pageContext.setAttribute("bathPath", bathPath);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta charset="utf-8">
  <title>人员权限管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <script type="text/javascript" src="${bathPath}/js/jquery-1.9.1.min.js" ></script>
  <link rel="stylesheet" href="${bathPath}/frame/layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<style type="text/css"> 
.layui-table-cell .layui-form-checkbox[lay-skin="primary"]{
     top: 50%;
     transform: translateY(-50%);
}
</style>
<body>

<form id="myform" class="layui-form layui-form-pane">
 <div class="demoTable" style="margin-top: 15px;margin-left: 20px;">

  <div class="layui-form-item">
	  <div class="layui-inline">
             <input type="hidden" id="depid" name="depid" value="${u.depid}" />
  
    
        <table class="param_table" style="width:640px;border-collapse:separate;margin-left:7px;margin-top:0px;">
	        	<tr>
	        		<!-- <td><button class="layui-btn site-demo-active get-checked" style="margin-left:2px;">人员门禁授权</button></td>
	        		<td><button class="layui-btn site-demo-active get-checked" style="margin-left:10px;">人员权限取消</button></td> -->
	        		<td style="font-size:8px;margin-top:100px;padding-left:15px;">
	        			<span>人员、卡号</span>
	        		</td>
	        		<td><input class="layui-input"  name="username"  id="username" autocomplete="off" style="width:130px;"></td>
	        		<td align="left" ><a class="layui-btn" data-type="reload">搜索</a></td>
	        		<td style="width:130px;height:50px;padding-left:10px;">
	        			<select name=""  id="" class="layui-form-label"> 
					    	<option value="">--请选择--</option>
					    	<option value="0">显示全部</option>
					    	<option value="1">已授权</option>
					    	<option value="2">未授权</option>
					    </select>
	        		</td>
	        		<td><input type="radio"  name="" lay-skin="primary" title="全部" checked="" value="0"></td>
	        		<td><input type="radio"  name="" lay-skin="primary" title="正常" value="0"></td>
	        		<td><input type="radio"  name="" lay-skin="primary" title="过期" value="0"></td>
	        	</tr>
	        </table>
		  
     </div>
  </div>
  
</div> 
</form>   
 <table class="layui-hide"  id="demo"></table>
<table class="layui-hide"  id="test"  lay-filter="test"></table>

<script src="${bathPath}/frame/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 --> 
<script type="text/html" id="barDemo">
  <div class="layui-btn-container">
	<button class="layui-btn layui-btn-xs" lay-event="upd">查看</button>
  </div>
</script>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add" id="a">人员门禁授权</button>
    <button class="layui-btn layui-btn-sm" lay-event="delete">人员权限取消</button>
  </div>
</script>
<script>
	layui.use('element', function() {
		var $ = layui.jquery, element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
		$('.site-demo-active').on('click', function() {
			var othis = $(this), type = othis.data('type');
			active[type] ? active[type].call(this, othis) : '';
		});

		//Hash地址的定位
		var layid = location.hash.replace(/^#test=/, '');
		element.tabChange('test', layid);

		element.on('tab(test)', function(elem) {
			location.hash = 'test=' + $(this).attr('lay-id');
		});

	});

	//查看弹出框
	function upd(d){
		//alert(d);
		top.layer.open({
			  title:'查看控制器、权限组',
			  title:'查询卡片',
			  title:'查看',
			  type: 2,
			  area:['900px', '400px'],
			  offset: ['180px','345px'] ,
			  content: '${bathPath}/aDKUserGroup/chaKanUserGroup.action?userid='+d
			}); 
	}
	</script>

<script>

//表格事件
layui.use('table', function(){
 //var parm = $('#myform').serialize(); //获取表单所有数据
  var table = layui.table;
  var layTableId="test";
  var flag=0; //判断表格是否在增加数据

//返回data数据给表格
 var laydata="";
 function getdata(parm){
	 $.ajax({
			type:"POST",
			data:parm,
			async:false,  //默认true,异步
			url:"${bathPath}/aDKUserInfo/selectAllc.action",
			success:function(data){
					laydata=data;
		    }
		});  
	 return laydata;
 }
 
 
 //搜索事件
 function selectall()
 {
	 var parm = $('#myform').serialize(); //获取表单所有数据\
	 alert(parm);
	  //alert(JSON.stringify(parm));
	 // alert(demoReload);
 	//这里以搜索为例
 	console.log(JSON.stringify(parm));
 	table.reload('test',{
  		data:getdata(parm),  //返回查询后的data直接赋值
  	    page: {
  	    curr: 1 //重新从第 1 页开始
  	  }
  	});
 	}
 
 
//监听头工具栏事件
	table.on('toolbar(test)', function(obj){
 var checkStatus = table.checkStatus(obj.config.id)
 ,data = checkStatus.data; //获取选中的数据
 //var length = table.cache[layTableId].length;   
 switch(obj.event){

  case 'add':   //删除一行
     if(data.length === 0){
    	 //if(checkbox === true){
       layer.msg('请选择人员');
     } else {
    	 //$("#a").click(function(){
    		   //alert(data.length);
    		  top.layer.open({
   			  title:'设置用户权限',
   			  type: 2,
   			  area:['900px', '500px'],
   			  offset: ['180px','345px'] ,
   			  content: '${bathPath}/aDKUserGroup/index1.action'
   			});  
    		//});
    	
    	 
     }
   break;
 
   case 'delete':   //删除一行
     if(data.length === 0){
       layer.msg('请选择一行');
     } else {
     	//alert(data);
     	layer.confirm("确定删除其权限么？", {btn: ['确定', '取消'], title: "提示"}, function(){
			 $.ajax({
				type:"POST",
				async:true,  //默认true,异步
				//url:"${bathPath}/aDKController/deletecontroller.action",  //后台增删改查的action
				data:"op=del&data="+JSON.stringify(data), //选中的数据信息
				success:function(data){
					if(data!="SUCCESS"){
						layer.msg(data);
						selectall();
					}
			    }
			}); 
     	});
     }
   break;

};
});

//监听行工具栏事件
	table.on('tool(test)', function(obj){
		var data = obj.data //获得当前行数据
	    ,layEvent = obj.event; //获得 lay-event 对应的值
	  if(layEvent === 'upd'){
		   //alert(data.userid)
		upd(data.userid);
		
	    } 
});
//监听排序
  table.on('sort(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
  if(obj.field!=null){
	  parm="sort="+obj.field
	  if(obj.type!=null){
		  parm+="&order="+obj.type;
	  }
  }
  table.reload('test', {
    initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
    ,data:getdata(parm)
  });
}); 
//文本框搜索
		  $('.demoTable .layui-btn').on('click', function(){
		    selectall();
		  });
		  
  //渲染表格
 table.render({
	    elem: '#test'
	    ,id: layTableId
	    ,url:'${bathPath}/aDKUserInfo/select.action?depid='+$("#depid").val()
	 	//,data:getdata()
	    ,toolbar: '#toolbarDemo' 
	    ,cellMinWidth:80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
	    ,width:690
	    ,size:'sm'//小表格
	    ,cols: [[
	    	{type: 'checkbox', fixed: 'left',align:'center',width:'5%'}
			/* ,{type: 'numbers',title:'序号', fixed: 'left',align:'center',width:'5%'} */
	      	,{field: 'userid',title:'人员编号', fixed: 'left',align:'center',width:'10%'}
	      	,{field: 'username',title:'人员名称', fixed: 'left',align:'center',width:'15%'}
	      	,{field: 'depName',title:'部门', fixed: 'left',align:'center',width:'15%'}
	      	,{field: 'telno',title:'电话', fixed: 'left',align:'center',width:'10%'}
	      	,{field: 'certnum',title:'证件号码', fixed: 'left',align:'center',sort:true,width:'10%',edit: 'text'}
	      	,{field: 'flag',title:'状态', fixed: 'left',align:'center',width:'10%',templet: function(row){
      			var ss="";
				if(row.flag==0){
					ss="正常";
				}
				if(row.flag==9){
					ss="注销";
				}
				return ss}}
	      	,{field: 'cardvaliddate',title:'有效期', fixed: 'left',align:'center',width:'15%'}
	      	,{field: 'caozuo',title:'操作', fixed: 'left',align:'center',width:'10%',toolbar: '#barDemo'} 
	    ]]
	    ,page: true //开启分页
	    ,limit:5  //默认十条数据一页
        ,limits:[5,10,20,30,50]  //数据分页条
	  }); 
});
</script>
</body>
</html>